package com.kuzan.autocloud.common.model.report;

import com.kuzan.autocloud.common.model.Base;
import com.kuzan.autocloud.common.model.form.FormField;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;


/**
 * <p>Description: </p>
 *
 * @author kuzank
 */
@Data
@NoArgsConstructor
@Entity
@Table(name = "sys_report_field")
public class ReportField extends Base {

    @Column(length = 32)
    private String report;
    @Column
    private double width;
    @Column(length = 12, columnDefinition = "varchar(10) default 'rfo_show'")
    private String operation = ReportFieldOperator.Show.getName();

    public static ReportField of(FormField formField, String report) {
        ReportField reportField = new ReportField();
        reportField.setTitle(formField.getTitle());
        reportField.setReport(report);
        reportField.setSort(getSortIncrement());
        return reportField;
    }

    /**
     * 报表字段操作
     */
    public enum ReportFieldOperator {
        pid("rfo"),

        Edit("rfo_edit"),
        Show("rfo_show"),
        Hidden("rfo_hidden");

        private String name;

        ReportFieldOperator(String name) {
            this.name = name;
        }

        public String value() {
            return name;
        }

        public String getName() {
            return name;
        }

    }
}
